package com.aiti.lulian.controller.newCard;

import com.aiti.base.core.base.controller.WebController;
import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.entity.newCard.CardMessage;
import com.aiti.lulian.service.CardMessageService;
import com.aiti.lulian.vo.newCard.CardMessageVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("new-card/message")
public class CardMessageController extends WebController {

    @Autowired
    private CardMessageService cardMessageService;

    @ApiOperation("查询未读消息总数")
    @GetMapping("/unread-count")
    public Message getMessageCount(@RequestParam("cardId") String cardId) {
        return Message.success(cardMessageService.getCount(cardId));
    }

    @ApiOperation("查询消息列表")
    @GetMapping("/list")
    public Message getMessageList(@RequestParam("cardId") String cardId, @RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        Page<CardMessage> page = this.startPage(pageNum, pageSize);
        List<CardMessageVo> list = cardMessageService.getPage(page, cardId);
        return Message.success(getPageResult(list, pageNum, pageSize, (int) page.getTotal()));
    }

    @ApiOperation("全部已读")
    @PutMapping("/read-all")
    public Message readAllMessage(@RequestBody CardMessage cardMessage) {
        cardMessageService.readAllMessage(cardMessage);
        return Message.success();
    }
}
